package com.jxrj.interaction.controller.teacher;

import com.alibaba.fastjson.JSONObject;
import com.jxrj.interaction.controller.BaseController;
import com.jxrj.interaction.entity.Teacher;
import com.jxrj.interaction.service.TeacherService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class TeacherLoginController extends BaseController {
    @Resource(name = "teacherService")
    private TeacherService teacherService;

    //登陆验证
    @ResponseBody
    @PostMapping("teacher/doLogin")
    public String checkLogin(HttpSession session,@RequestBody Teacher o) {
        logger.info("教师登录验证");
        Teacher teacher = teacherService.login(o.getEmail(),o.getPassword());

        JSONObject object = new JSONObject();
        if(teacher == null){
            logger.info("登录验证失败");
            object.put("success",false);
        } else {
            logger.info("登录验证成功，教师ID传入会话");
            session.setAttribute("teacherId",teacher.getId());
            object.put("success",true);
        }

        return object.toJSONString();
    }
}
